var Project = {
	item: null,
	messageIndex: 0,
	myScroll: null,
	flag: true,
	singHeight: 0,
	projectIndexInit: function(category){ 
		var listFn = function(category){
			if (CurrentUser){
				$ajax({
	                "url": "/user/detail",
	                "data": {
	                    _id: CurrentUser._id
	                },
	                success: function(res){
	                	SetLS("user",res.result);
	                    CurrentUser = res.result;
						list(category);	
					}
				});	
			} else 
				list(category);	
			function list(category){
				$ajax({
	               	url: "/direction/listProject",
	               	data: {
	                    category : category,
	                    full: true
	               	},
					success: function(res) {
						var data = res.result;			
						var project = "";
						for (var i = 0; i < data.length; i ++){
							var desc = '';
							if (data[i].desc)
								desc = data[i].desc.length>42?data[i].desc.substr(0,42) + "...":data[i].desc;
							else
								desc = "暂无描述";

							 var flag = false;
							 var content = '';
							if (CurrentUser&&CurrentUser.project){
								for (var j = 0; j < CurrentUser.project.length; j ++){
									if (data[i]._id == CurrentUser.project[j]._id)
										flag = true;
								}
							}	
							if (flag)
								content = '<div class="ufp8 ub ub-ac c_gre"><span class="uba uc-a1 b_green upp3 ufp9">已选</span></div>';
							project += 	'<div class="ub ubb b_gra upp7" ontouchstart="zy_touch()" onclick="Project.jumpDetail(\'' + data[i]._id + '\',\'' + data[i].name + '\')">' + 
										'	<div class="ub-img7 uw50 imgScale" style="background-image:url(' + Core.id2url(data[i].picture,"photo") + ')"></div>' + 
										'	<div class="ub ub-f1 ub-ver uml_p3">' + 
										'		<div class="ub">' + 
										'			<div class="ub-f1 upp5 ut-s">' + data[i].name + '</div>' + 
										content + 
										'		</div>' + 
										'		<div class="ub ufp8 upp5 ub-ac ub-pc">' + 
										'			<div class="ub-img1 uw1p5 uh1p5 im_ico_origin"></div>' + 
										'			<div class="ub-f1 ut-s">&nbsp;创建时间 : ' + (new Date(data[i].create)).pattern('yyyy-MM-dd') + '</div>' + 
										'		</div>' + 
										'		<div class="ufp8 upp5 t-gra line-hei1p5">' + desc + '</div>' + 
										'	</div>' + 
										'</div>';
							//Res.gnproject(Core.id2url(data[i]),data[i].name,data[i].organization);			
						}
						if(project.length === 0)
						   project ='<div class="ub-f1 ub ub-ver ub-ac ub-pc uw100 upt_percent30">' + 
									'	<div class="uc-a2 bc_green upp5 t-wh uw50 tx-c">该方向下暂无相应项目！</div>' + 
									'</div>';
						//$("#projectList").html(project);
						$("#projectList").html(project);
						$(".imgScale").height($(".imgScale").width()*7/10+"px");
					}
				});
			}		
		}
		listFn(category);
	},
	jumpDetail: function(id,name){
		SetLS("projectId",id);
		SetLS("projectName",name);
		OpenNewWin("index_project_detail");
	},
	projectDetailInit: function(){ 
		var id = GetLS("projectId");
		$ajax({
           url: "/project/detail",
           data: {
                _id: id
           },
           success: function(res){
				var project = res.result;
				Project.item = project;
				SetLS("projectId",project._id);
				$("#player").html('<img id="imgScaleCert" src="' + Core.id2url(project.picture,'photo') + '" class="uw100">');
				$("#imgScaleCert").height($("#imgScaleCert").width()*9/16+"px");
				$("#projectName").text(project.name);
				$("#projectDes").text(project.desc);
				var projectPhoto = '';
				for (var j = 0; j < project.photo.length; j ++){
					projectPhoto += '<img src="' + Core.id2url(project.photo[j],'photo') + '" class="uw100 ump50">';
				}
				$("#projectPhoto").html(projectPhoto);
				var data = project.course;
				var course = '';
				for (var i = 0; i < data.length; i ++){
					var desc = data[i].desc.length>42?data[i].desc.substr(0,42) + "...":data[i].desc;
					course += '<div data-id="' + data[i]._id + '" class="ub ub-f1 ubb b_gra up1" ontouchstart="zy_touch()" onclick="Project.jumpDetailCourse(\'' + data[i]._id + '\',\'' + data[i].name + '\')">' + 
								'	<div class="imgScale ub-img7 uw50" style="background-image:url(' + Core.id2url(data[i]) + ')"></div>' + 
								'	<div class="ub ub-f1 ub-ver">' + 
								'		<div class="upp5 ut-s">' + data[i].name + '</div>' + 
								//'		<div class="ub ufp8">' + 
								//'			<div class="ub-f1 ub upp5 ub-ac ub-pc">' + 
								//'				<div class="ub-img1 uw1p5 uh1p5 im_ico_teach"></div>' + 
								//'				<div class="ub-f1">&nbsp;讲师 : ' + (data[i].teachers[0]?data[i].teachers[0].name:"暂无讲师") + '</div>' + 
								//'			</div>' + 
								//'			<div class="ub-f1 ub upp5 ub-ac ub-pc">' + 
								//'				<div class="ub-img1 uw1p5 uh1p5 im_ico_hours"></div>' + 
								//'				<div class="ub-f1">&nbsp;课时 : ' + data[i].classHour + '课时</div>' + 
								//'			</div>' + 
								//'		</div>' + 
								'		<div class="ufp9 upp5 t-gra line-hei1p5">' + desc + '</div>' + 
								'	</div>' + 
								'</div>';
					//Res.gnCourse(Core.id2url(data[i]),data[i].name,(data[i].teachers[0]?data[i].teachers[0].name:"暂无讲师"),data[i].classHour,des,data[i]._id,Course.jumpDetail);			
				}
				$("#course").html(course);
				$(".imgScale").height($("#imgScaleCert").width()*7/10/2+"px");
				//讨论
				//Project.messaageInit(project._id);
			}
		});
	},
	messaageInit: function(id){
		$ajax({
			url: "/message/list",
			data: {
				to: id,
				start: Project.messageIndex,
				count: Res.count
			},
			success: function(res){
				Project.messageIndex += Res.count;
				var data = res.result.results;
				//console.log(JSON.stringify(data));
				var html = "";
				var length = data && data.length || 0;
				if (data.length == 0){ 
					html = 	'<div id="defmess" class="ub ub-ver ub-f1 ub-ac ub-pc ufp9" style="margin-top:3em;">' + 
							'	<div class="uh12 uw12 ub-img7 im_no_exam"></div>' + 
							'	<div class="uf1p3 upp5 c_gra1">这里还很安静？赶快发起讨论吧！</div>' + 
							'</div>';
				}else {
					for (var i = length-1; i >= 0; i--){
						html += Project.getMessageHtml(data[i]);
					}
				}
				$("#scroller-content").html(html);
				Project.iscrollLoaded();
				Project.myScroll.scrollTo(0,Project.myScroll.maxScrollY); 
			}
		});
	},
	iscrollLoaded: function(){
        var myScroll,
            upIcon = $("#up-icon"),
            downIcon = $("#down-icon");
            
        myScroll = new IScroll('#wrapper', { probeType: 3, mouseWheel: true });
        
        myScroll.on("scroll",function(){
            var y = this.y,
                maxY = this.maxScrollY - y,
                downHasClass = downIcon.hasClass("reverse_icon"),
                upHasClass = upIcon.hasClass("reverse_icon");
            
            if(y >= 40){
                !downHasClass && downIcon.addClass("reverse_icon");
                return "";
            }else if(y < 40 && y > 0){
                downHasClass && downIcon.removeClass("reverse_icon");
                return "";
            }
            
            if(maxY >= 40){
                !upHasClass && upIcon.addClass("reverse_icon");
                return "";
            }else if(maxY < 40 && maxY >=0){
                upHasClass && upIcon.removeClass("reverse_icon");
                return "";
            }
        });
        
        myScroll.on("slideDown",function(){
            if(this.y > 40){
            	if (Project.flag){
            		$("#scroller-pullDown").addClass("flip").addClass("loading");
                	Project.messagePrepend(this);
            	}
                upIcon.removeClass("reverse_icon")
            }
        });
        
        myScroll.on("slideUp",function(){
            if(this.maxScrollY - this.y > 40){
                //alert("slideUp");
                upIcon.removeClass("reverse_icon")
            }
        });
        Project.myScroll = myScroll;
	},
	messagePrepend: function(myScroll){
		Project.flag = false;
		$ajax({
			url: "/message/list",
			data: {
				to: GetLS("projectId"),
				start: Project.messageIndex,
				count: Res.count
			},
			success: function(res){
				if (res.result.results.length == 0){
					Project.flag = false;
					$("#scroller-pullDown").removeClass("flip").removeClass("loading");
					return $alert("没有消息了");
				} else
					Project.flag = true;
				Project.messageIndex += Res.count;
				var data = res.result.results;
				var html = '';
				$.each(data,function(i,item){
					html +=  Project.getMessageHtml(item);
				});
				$("#scroller-content").prepend(html);
				setTimeout(function(){myScroll.refresh()}, 800);
				setTimeout(function(){$("#scroller-pullDown").removeClass("flip").removeClass("loading");}, 800);
				
			}
		});
	},
	getMessageHtml: function(item) {
		var html = "";
		var content = "";
		if (item.from == CurrentUser._id) {
			if (item.media == 0) {
				content = '	<div class="talk_ctn" style="float:right">' +
							'      	<div class="upp5 wb_a talk_ctn right umw3 uml_2 c_gra umw12 umh_4" style="float:none;">' +
							'         	<div class="uw1p5 uh1p5 ub_img im_talk_right" style="position: absolute;top: 0;right: -1em;"></div>' + 
							'			<div class="ub ub-ver">' + 
							'				<div class="ub-f1 umh_3">' + item.content + '</div>' + 
							'				<div class="ufp8 tx-l c_gra1 upt_p5">' + Core.offsetDate(item.create) + '</div>' +
							'			</div>' + 
							'     	</div>' +
							'</div>';
			} else if (item.media == 1) {
				content = '<div class="uw7 uh5 ub_img_cover photoBrowserEvent" data-url="'+ item.content +'" style="background-image:url('+ Core.id2url(item.content, "photo") +'); background-size:cover; float:right" ontouchstart="zy_touch()" onclick="ImageBrowser(\'' + item.content + '\')"></div>'+
							'<div class="ufp8 tx-r" style="clear:both">' + Core.offsetDate(item.create) + '</div>';
			}
			html += '<div class="ub-f1 ub uptb_1">' +
				'	 <div class="uw3"></div>' +
				'    <div class="ub-f1 upr_1">' + content +
				'    </div>' +
				'	<div class="ub ub-ac ub-ver" style="margin-top: -4%;min-width: 4em;">' + 
				'    	<div class="uw3 uh3 umar-tp5 ub_img_cover uc-ap50" style="background-image:url(\'' + Core.id2url(CurrentUser) + '\');"></div>' +
				'    	<div class="umar-tp5 uml_p5 c_gra1">' + (CurrentUser.name||CurrentUser.username) + '</div>' +
				'	</div>' + 
				'</div>';
		} else {
			item.category = Role.STUDENT;
			item.photo = item.userPhoto;
			if (item.media == 0) {
				content = 	'<div class="talk_ctn">' +
						  	'		<div class="upp5 wb_a talk_ctn left umw3 umar-r2 c_gra umw12 umh_4" style="">' +
						  	'			<div class="uw1p5 uh1p5 ub_img im_talk_left" style="position: absolute;top: 0;left: -1em;"></div>' + 
						  	'			<div class="ub ub-ver">' + 
							'				<div class="ub-f1 umh_3">' + item.content + '</div>' + 
							'				<div class="ufp8 tx-l c_gra1 upt_p5">' + Core.offsetDate(item.create) + '</div>' +
							'			</div>' + 
						  	'		</div>' +
						  	'</div>';
			} else if (item.media == 1) {
				content = '<div class="uw7 uh5 ub_img photoBrowserEvent" data-url="'+ item.content +'" style="background-image:url('+ Core.id2url(item.content, "photo") +'); background-size:cover;" ontouchstart="zy_touch()" onclick="ImageBrowser(\'' + item.content + '\')"></div>'+
							'<div class="ufp8 tx-l" style="clear:both">' + Core.offsetDate(item.create) + '</div>';
			}
			html += '<div class="ub-f1 ub uptb_1">' +
					'	<div class="ub ub-ac ub-ver" style="margin-top: -4%;min-width: 4em;">' + 
					'    	<div class="uw3 uh3 umar-tp5 ub_img_cover uc-ap50" style="background-image:url(\'' + Core.id2url(item) + '\');"></div>' +
					'    	<div class="umar-tp5 umr_p5 c_gra1">' + item.userName + '</div>' +
					'	</div>' + 
					'    <div class="ub-f1 upl_1">' + content +
					'    </div>' +
					'	 <div class="uw3"></div>' +
					'</div>';
		}
		return html;
	},
	jumpDetailCourse: function(id,name){ 
		SetLS("courseId",id);
		SetLS("courseName",name);
		$ajax({
            "url": "/user/detail",
            "data": {
                _id: CurrentUser._id
            },
            success: function(res){
                SetLS("user",res.result);
                CurrentUser = res.result;
                var flag = false;
				if (CurrentUser&&CurrentUser.course){
					for (var i = 0; i < CurrentUser.course.length; i ++){
						if (id == CurrentUser.course[i]._id)
							flag = true;
					}
				}	
				if (flag)
					OpenNewWin("study_myCourse_detail");
				else
					OpenNewWin("index_course_detail");
            }
        });
		
	},
	jumpSend: function(){
		if (!CurrentUser)
			return $alert("您还未登陆，不能参加讨论");
		var flag = false;
		var projectId = GetLS("projectId");
		for (var i = 0; i < CurrentUser.project.length; i ++){
			if (projectId == CurrentUser.project[i]._id)
				flag = true;
		}
		if (!flag)
			return $alert("您尚未拥有此项目，添加后才可参与讨论，是否添加？",function(){
				$ajax({
                    url:"/user/setCourseProject", 
                    data:{
                        field: "project",
                        value: projectId
                    }, 
                    success:function(res){
                    	$ajax({
                    		"url": "/user/detail",
                    		"data": {
                    			_id: CurrentUser._id
                    		},
                    		success: function(res){
                    			SetLS("user",res.result);
                    			CurrentUser = res.result;
                    			add();
                    		}
                    	});
                    }   
                });  
			});
		else
			add();

		function add(){
			var msgcontent = $("#msg").val();
			if (msgcontent == "") {
				$alert("发送内容不能为空");
				return;
			}
			if (msgcontent.length > 200) {
				$alert("字数已超过最多字数限制");
				return;
			}
			$("#msg").val("");

			CCall("Project.send('" + msgcontent + "');");
		}	
	},
	send: function(msgcontent){
		$ajax({
			url: "/message/add",
			data: {
				to: GetLS("projectId"),
				media: 0,
				content: msgcontent
			},
			success: function(res){
				if ($("#defmess").length > 0)
					$("#defmess").remove();
				$("#scroller-content").append(Project.getMessageHtml(res.result));
				setTimeout(function(){Project.myScroll.refresh()}, 800);
				var singHeight = $("#scroller-content>div:eq(0)").height();
				Project.myScroll.scrollTo(0,Project.myScroll.maxScrollY-singHeight-10); 
			}
		});
	},
	jumpKity: function(){
		var projectId = GetLS("projectId");
		if (!CurrentUser)
			return;
		else {
			var flag = false;
			for (var i = 0; i < CurrentUser.project.length; i ++){
				if (projectId == CurrentUser.project[i]._id)
					flag = true;
			}
			if (flag)
				OpenNewWin("minder/edit.html?id="+GetLS("projectId"));
			else{
				$alert("尚未拥有此项目，是否添加？",function(){
	                $ajax({
	                    url:"/user/setCourseProject", 
	                    data:{
	                        field: "project",
	                        value: projectId
	                    }, 
	                    success:function(res){
	                    	$ajax({
	                    		"url": "/user/detail",
	                    		"data": {
	                    			_id: CurrentUser._id
	                    		},
	                    		success: function(res){
	                    			SetLS("user",res.result);
	                    			CurrentUser = res.result;
	                    			PCall("father","CCall('Project.projectIndexInit()')");
	                    			OpenNewWin("minder/edit.html?id="+GetLS("projectId"));
	                    		}
	                    	});
	                    }   
	                });  
	            }); 
	        }      
		}
		
		//window.location.href = "kity.html";
	},
	showCover: function(type,obj,text,requirement){
		var content = '';
		var coverinfo = GetLS("coverinfo");
		if (type == "text"){
			if (requirement){
				content = 	'<p class="ufp9 ">介绍: ' + (obj?obj:"暂无") + '</p>' + 
							'<p class="ufp9 ">要求: ' + (requirement?requirement:"暂无") + '</p>';
			} else {
				content = '<p class="ufp9 ">' + obj?obj:"暂无" + '</p>';
			}
		}
		else if (type == "photo"){
			content = "<div id='photoList'>";
			var photos = coverinfo.photos;
	        for (var i = 0; i < photos.length; i ++){
	        	content += "<div class='tx-c ump50'><img src='" + Core.id2url(photos[i],"photo") + "' style='width:80%;'></div>";
	        }
	        if (photos.length == 0)
	        	content += "<div class='tx-c ump50'><p>暂无</p></div>";
        	content +="</div>";
		}else if (type == "video"){
			content = "<div id='video'><p style='color: #385487;text-decoration: underline;' onclick=\"Project.openVideo(\'" + coverinfo.video.url + "\');\">" + coverinfo.video.name + "</p></div>";
			if (!coverinfo.video)
	        	content = "<div class='tx-c ump50 '><p>暂无</p></div>";
		}else if (type == "docs"){
			content = "<div id='docsList'>";
			var docs = coverinfo.docs;
	        for (var i = 0; i < docs.length; i ++){
	        	content += "<div class='tx-c ump50 '><p style='color: #385487;text-decoration: underline;' onclick=\"Project.openMaterial(\'" + docs[i].name + "\',\'" + docs[i].url + "\');\">" + docs[i].name + "</p></div>";
	        }
	        if (docs.length == 0)
	        	content += "<div class='tx-c ump50 '><p>暂无</p></div>";
        	content +="</div>";
		}else if (type == "attachs"){
			content = "<div id='attachsList'>";
			var attachs = coverinfo.attachs;
	        for (var i = 0; i < attachs.length; i ++){
	        	content += "<div class='tx-c ump50'><p style='color: #385487;text-decoration: underline;' onclick=\"Project.openMaterial(\'" + attachs[i].name + "\',\'" + attachs[i].url + "\');\">" + attachs[i].name + "</p></div>";
	        }
	        if (attachs.length == 0)
	        	content += "<div class='tx-c ump50'><p>暂无</p></div>";
        	content +="</div>";
		}else if (type == "videos"){
			content = "<div id='videosList'>";
			var videos = coverinfo.videos;
	        for (var i = 0; i < videos.length; i ++){
	        	content += "<div class='tx-c ump50'><p style='color: #385487;text-decoration: underline;' onclick=\"Project.openVideo(\'" + videos[i].url + "\');\">" + videos[i].name + "</p></div>";
	        }
	        if (videos.length == 0)
	        	content += "<div class='tx-c ump50'><p>暂无</p></div>";
        	content +="</div>";
		}
		else if (type == "materials"){
			content = "<div id='materialsList'>";
			var materials = coverinfo.materials;
	        for (var i = 0; i < materials.length; i ++){
	        	content += "<div class='tx-c ump50 '><p style='color: #385487;text-decoration: underline;' onclick=\"Project.openMaterial(\'" + materials[i].url + "\',\'" + materials[i].url + "\');\">" + materials[i].name + "</p></div>";
	        }
	        if (materials.length == 0)
	        	content += "<div class='tx-c ump50 '><p>暂无</p></div>";
        	content +="</div>";
		} else if (type == "exam"){
			content = "<div id='examHL' class='tx-c ump50 '></div>";
			$ajax({
				url: "/examine/detailKnowledge",
				data:{
					_id: coverinfo.kid
				},
				success: function(res){
					$("#cover").remove();
					var content = "<div id='examHL' class='ump50'></div>";
					show(content,text);
					SetLS("exam",res.result);
					Project.examFn("examHL",res.result);
				}
			});
		}
		show(content,text);
		function show(content,text){
			var cover = '<div id="cover" class="fancybox-overlay fancybox-overlay-fixed" style="width: auto; height: auto; display: block;overflow:auto;font-size:0.4em;">' + 
				        '    <div class="animated zoomInUp fancybox-wrap fancybox-desktop fancybox-type-image fancybox-opened" tabindex="-1" style="width: 80%; height: auto; position: absolute; top: 10%; left: 10%; opacity: 1; overflow: visible;">' + 
				        '        <div class="fancybox-skin" style="padding: 30px; width: auto; height: auto;">' + 
				        '            <div class="fancybox-inner uf3p7" style="overflow: visible; width: 100%; height: auto;">' + 
				        content + 
				        '            </div>' + 
				        '            <div class="fancybox-title fancybox-title-float-wrap">' + 
				        '                <span class="child">' + text + '</span>' + 
				        '            </div>' + 
				        '            <a id="close" class="fancybox-item fancybox-close" href="javascript:;"></a>' + 
				        '        </div>' + 
				        '    </div>' + 
				        '</div>';
			$("body").append(cover);	        
			$("#cover,#close").click(function(){
				$("#cover").remove();
			});
			$('.fancybox-wrap').click(function(event){
				event.stopPropagation();
			});
		}	
	},
	openPdf: function(name,url){
		window.open(Core.ATTACH_VER +url);
	},
	getKityContentHtml: function(){
		return "<div id='dataHtml' class='form form-horizontal validate-form' style='margin-bottom: 0;'>" + 
    		   "     <div class='control-group'></div>" + 
               "</div>";
	},
	getBlockContentHtml: function(desc,requirement,photos,video,docs,attachs){
	    var coverinfo = new Object();
	    coverinfo.desc = desc;
	    coverinfo.requirement = requirement;
	    coverinfo.photos = photos;
	    coverinfo.video = video;
	    coverinfo.docs = docs;
	    coverinfo.attachs = attachs;
	    SetLS("coverinfo",coverinfo);
	    var html =  "<div id='otypeList' class='tx-c'>";
    	if (desc&&desc!="暂无")
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"text\",\"" + desc + "\",\"介绍文字和要求\",\"" + requirement + "\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_01 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>介绍</label>" + 
	               	"     </div>";
	    if (photos.length)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"photo\",\"" + photos + "\",\"图片\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_03 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>图片</label>" + 
	               	"     </div>";
       	if (video)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"video\",\"" + video + "\",\"视频\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_04 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>视频</label>" + 
	               	"     </div>";
	    if (docs.length)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"docs\",\"" + docs + "\",\"文档\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_05 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>文档</label>" + 
	               	"     </div>";
	    if (attachs.length)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"attachs\",\"" + attachs + "\",\"资源\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_06 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>资源</label>" + 
	               	"     </div>";
           	html += "     <div class='control-group ump50' onclick='OpenNewWin(\"../index_message\")'>" + 
	               	"        <div class='ub_img100 im_set_icon1 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>评论</label>" + 
	               	"     </div>" + 
              		"</div>";      
	    return html;           
	},
	getChapContentHtml: function(name,desc){
		var coverinfo = new Object();
	    coverinfo.name = name;
	    coverinfo.desc = desc;
	    SetLS("coverinfo",coverinfo);
	    var html =  "<div id='otypeList' class='tx-c'>";
	    if (name)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"text\",\"" + name + "\",\"章节名称\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_09 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>名称</label>" + 
	               	"     </div>";
       	if (desc)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"text\",\"" + desc + "\",\"章节描述\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_07 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>描述</label>" + 
	               	"     </div>";
           	html += "     <div class='control-group ump50' onclick='OpenNewWin(\"../index_message\")'>" + 
	               	"        <div class='ub_img100 im_set_icon1 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>评论</label>" + 
	               	"     </div>" + 
              		"</div>";      
	    return html;   
	},
	getPointContentHtml: function(desc,target,videos,materials,data){ 
	    var coverinfo = new Object();
	    coverinfo.desc = desc;
	    coverinfo.target = target;
	    coverinfo.videos = videos;
	    coverinfo.materials = materials;
	    coverinfo.kid = data._id;
	    coverinfo.chid = data.chid;
	    coverinfo.cid = data.cid;
	    SetLS("coverinfo",coverinfo);
	    var html =  "<div id='otypeList' class='tx-c'>";
	    if (desc&&desc!="暂无")
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"text\",\"" + desc + "\",\"知识点描述\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_07 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>描述</label>" + 
	               	"     </div>";
       	if (target&&target!="暂无")
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"text\",\"" + target + "\",\"知识点目标\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_08 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>目标</label>" + 
	               	"     </div>";
       	if (videos.length)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"videos\",\"" + videos + "\",\"视频\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_04 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>视频</label>" + 
	               	"     </div>";
       	if (materials.length)
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"materials\",\"" + materials + "\",\"教材\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_09 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>教材</label>" + 
	               	"     </div>";
           	html += "     <div class='control-group ump50' onclick='Project.showCover(\"exam\",\"点击开始练习\",\"每课一练\")'>" + 
	               	"        <div class='ub_img100 im_icon_kity_08 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>考试</label>" + 
	               	"     </div>" + 
           			"     <div class='control-group ump50' onclick='OpenNewWin(\"../index_message\")'>" + 
	               	"        <div class='ub_img100 im_set_icon1 cover_icon uw3 uh3' style='margin:0 auto;'></div>" + 
	               	"		 <label for='validation_secret'>评论</label>" + 
	               	"     </div>" + 
              		"</div>";      
	    return html;          
	},
	openMaterial: function(name,url){ 
		Download.download(Core.ATTACH_VER+url, "attach/"+name, function(status){
			if (status == 1) {
				uexDocumentReader.openDocumentReader("wgt://data/attach/"+name);
			}
		}, true);
	},
	openVideo: function(url){ 
		uexVideo.open(Core.ATTACH_VER+url, 1);
	},
	examFn: function(htmlId,res){ 
		var SINGLE_CHOICE = '',MULTIPLE_CHOICE = '',JUDGE = '',FILL = '',SUBJECTIVE = '',LIGATURE = '',SORT = '';
		var SINGLE_NUM = 0,MULTIPLE_NUM = 0,JUDGE_NUM = 0,FILL_NUM = 0,SUBJECTIVE_NUM = 0,LIGATURE_NUM = 0,SORT_NUM = 0;
		for (var i = 0; i < res.length; i ++){
			if (res[i].QuestionType == EXAMTYPE.SINGLE_CHOICE){
				SINGLE_NUM ++;
				SINGLE_CHOICE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>'  +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + SINGLE_NUM + "、" + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SINGLE_CHOICE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      		
                    SINGLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		SINGLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		             SINGLE_CHOICE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +     
		             					'<div class="issbor"></div>' + 	
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				MULTIPLE_NUM ++;
				MULTIPLE_CHOICE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + MULTIPLE_NUM + "、"  + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	MULTIPLE_CHOICE += '<li>' + 
                                    '<label><input type="checkbox" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    MULTIPLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4><div style="float:left;">';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		MULTIPLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                MULTIPLE_CHOICE +=	'</div><div class="hide tipEvt ub" style="padding:1em;clear:both;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                					'<div class="issbor"></div>' + 	 
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.JUDGE){
				JUDGE_NUM ++;
				JUDGE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + JUDGE_NUM + "、" + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	JUDGE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    JUDGE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"<img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		JUDGE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                JUDGE +='<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                		'<div class="issbor"></div>' + 	       
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.FILL){
				FILL_NUM ++;
				FILL += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div>' + FILL_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<label><input class="uba uw90 uh2 ump50 uf1p1 upp3" type="text" id="' + res[i]._id + '"></label>';
                    			for ( var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    				FILL += '<input type="hidden" id="' + res[i].QuestionOptionList[j].Id + '" value="' + res[i].QuestionOptionList[j].Content + '">';
                    			}
                   	FILL += '</ul>' + 
                   			'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                   			'<div class="issbor"></div>' + 	
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.SUBJECTIVE){
				SUBJECTIVE_NUM ++;
				SUBJECTIVE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div>' + SUBJECTIVE_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<label><textarea class="uf1p1 upp3 uw90" id="' + res[i]._id + '"></textarea></label>';
                    			for ( var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    				SUBJECTIVE += '<input type="hidden" id="' + res[i].QuestionOptionList[j].Id + '" value="' + res[i].QuestionOptionList[j].Content + '">';
                    			}
                   	SUBJECTIVE += '</ul>' + 
                   			'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                   			'<div class="issbor"></div>' + 	
                        '</div>';       
			}
			else if (res[i].QuestionType == EXAMTYPE.LIGATURE){
				LIGATURE_NUM ++;
				LIGATURE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + LIGATURE_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<div class="matchByLineBox mlBoxCol">';
                    			var left = '<div class="matchSide matchSideQue">';
                    			var right = '<div class="matchSide matchSideAns">';
                    			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
	                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
	                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
	                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            }
	                            left += '</div>';
	                            right += '</div>';
                   			LIGATURE += left + right + 
                   			'</ul>' + 
                   			'<div class="issbor"></div>' + 	
                   		'</div>'; 
                        LIGATURE += '<h4 class="hide tipEvt c-wh c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;font-weight: normal;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>点击下面内容查看正确答案 : </span></h4>' + 
                        		'<ul class="hide tipEvt c-wh" style="background-color: #FFF;font-size: 1em;">' + 
                        			'<div class="matchByLineBox mlBoxCol" style="width:75%;">';
                        			var left = '<div class="matchSide matchSideQue">';
                        			var right = '<div class="matchSide matchSideAns">';
                        			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
		                            		for (var l = 0; l < res[i].QuestionOptionList.length; l ++){
		                            			if (res[i].QuestionOptionList[l].OrderNum == res[i].QuestionOptionList[j].OrderNum+1)
		                            				var ans = res[i].QuestionOptionList[l].Id;
		                            		}
		                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0" ans="' + ans + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
		                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            }
		                            left += '</div>';
		                            right += '</div>';
                       			LIGATURE += left + right + 
                       			'</ul>';   
                       	LIGATURE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                       				'<div class="issbor"></div>'; 
                        		   
			}
			else if (res[i].QuestionType == EXAMTYPE.SORT){
				SORT_NUM ++;
				//冒泡排序,用于正确答案
				var temp = 0;
				var targetArr = res[i].QuestionOptionList;
	            for(var k = 0;k<targetArr.length;k++){
	                for(var j = k;j<targetArr.length;j++){
	                    if(targetArr[k].OrderNum>targetArr[j].OrderNum){
	                        temp = targetArr[k];
	                        targetArr[k] = targetArr[j];
	                        targetArr[j] = temp;
	                     }
	                 }
	            }
				SORT += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<h5 style="margin: 1em 0em 1em 7.5%;position:relative;"><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + SORT_NUM + "、" + res[i].Content + '</h5>' + 
                            '<div class="custom_order" id="custom_order">' + 
		                    '    <div class="custom_sort_form">' + 
		                    '        <ul class="sort_div" id="sort_div" style="padding:1em;">';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SORT += '<li class="ub" id="' + res[i].QuestionOptionList[j].Id + '" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;">' + 
                                '    <div class="v_middle ub-f1" id="' + res[i].QuestionOptionList[j].Id + '_h" style="cursor: move;">' + res[i].QuestionOptionList[j].Content + '</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.topMove()">上移</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.bottomMove()">下移</div>' + 
                                '</li>';
                    }      
	                    SORT += '	 </ul>' + 
	                    		'<div class="issbor"></div>' + 	
			                    '<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
			                		for (var j = 0; j < targetArr.length; j ++){
			                        	SORT += '<li class="hide tipEvt" id="' + targetArr[j].Id + '" data-ordernum="' + targetArr[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;width:70%;margin:0.5em auto;background-color: #FFF;">' + 
				                                '    <div class="v_middle" id="' + targetArr[j].Id + '_h" style="cursor: move;">' + targetArr[j].Content + '</div>' + 
				                                '</li>';
		                        	}
	                    	SORT +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
	                    			'<div class="issbor"></div>' + 	
		                        '</div>' + 
		                    '</div>' + 
		                '</div>';            
			}
		}
		var num = 0;
		SINGLE_CHOICE = SINGLE_NUM>0?('<h3>' + Course.num[num] + '单选题</h3>' + SINGLE_CHOICE):"";num = SINGLE_NUM>0?num+1:num;
		MULTIPLE_CHOICE = MULTIPLE_NUM>0?'<h3>' + Course.num[num] + '多选题</h3>' + MULTIPLE_CHOICE:"";num = MULTIPLE_NUM>0?num+1:num;
		JUDGE = JUDGE_NUM>0?'<h3>' + Course.num[num] + '判断题</h3>' + JUDGE:"";num = JUDGE_NUM>0?num+1:num;
		FILL = FILL_NUM>0?'<h3>' + Course.num[num] + '填空题</h3>' + FILL:"";num = FILL_NUM>0?num+1:num;
		SUBJECTIVE = SUBJECTIVE_NUM>0?'<h3>' + Course.num[num] + '问答题</h3>' + SUBJECTIVE:"";num = SUBJECTIVE_NUM>0?num+1:num;
		LIGATURE = LIGATURE_NUM>0?'<h3>' + Course.num[num] + '匹配题</h3>' + LIGATURE:"";num = LIGATURE_NUM>0?num+1:num;
		SORT = SORT_NUM>0?'<h3>' + Course.num[num] + '排序题</h3>' + SORT:"";

		var html = SINGLE_CHOICE + MULTIPLE_CHOICE + JUDGE + FILL + SUBJECTIVE + LIGATURE + SORT;
		if (html)
			html += '<div class="uw80 up1 uc-a uf1p2 tx-c" onclick="Project.examSubmit();" style="background-color:#5f7ec7;color:white;margin:1em auto;">完成</div>';
		$("#" + htmlId).html(html);
		$(".tipEvt,.scoview").removeClass("ub");
		$(".scoview").addClass("ub");
		$("#examHL input").click(function(){ 
			$(this).parents("ul").find("input").each(function(i){ 
				if ($(this).prop("checked"))
					$(this).parents("li").css("background-color"," #ddebf9");
				else
					$(this).parents("li").css("background-color"," #f5f5f5");
			})	
		});;	
		// 初始化连线canvas
		var mblBoxs=$(".matchByLineBox");
		mblArr=[];//全局 存储所有mbl实例
		mblBoxs.each(function(x){
			var mbl=new MatchByLine(mblBoxs.eq(x));
			mbl.init();
			mblArr.push(mbl);
		});
		// 初始化拖动排序
		initDrag();
	},
	examSubmit: function(flag){ 
		var data = new Object();
		data.isLabour = false;
		data.questions = new Array();
		data.errSet = new Array();
		var score = 0;
		var nullQuesNum = '';
		var trueNum = 0;
		$("#examHL").find(".cnt").each(function(i){
			data.questions[i] = new Object();
			data.questions[i] = GetLS("exam")[$(this).data("num")];
			data.questions[i].trueOrFalse = false;
			data.questions[i].cid = GetLS("courseId");
			var QuestionType = $(this).data("questiontype");
			if (QuestionType == EXAMTYPE.SINGLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else
					data.errSet.push(data.questions[i]);	
				if ($(this).find("input[type='radio']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				var flag = false;
				$(this).find("input[type='checkbox']").each(function(j){
					if ($(this).data("ifrightanswer") && $(this).prop("checked")){
						flag = true;
					} else if (($(this).data("ifrightanswer") && !$(this).prop("checked"))|| (!$(this).data("ifrightanswer") && $(this).prop("checked"))){
						flag = false;
						return false;
					}
				});
				$(this).find("input[type='checkbox']:checked").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='checkbox']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.JUDGE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='radio']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.LIGATURE){
				var $evt = $(this);
				var flag = false;
				var nullFlag = false;
				$(this).find(".matchSideQue .matchOne").each(function(j){
					if ($(this).data("ordernum") == ($("#" + $(this).attr("ans")).data("ordernum") - 1)){
						flag = true;
					}else{
						flag = false;
						return false;
					}
				});
				data.questions[i].stuAnswer = new Array();
				$(this).find(".matchSideQue .matchOne").each(function(j){
					if ($(this).attr("ans"))
						nullFlag = true;
					data.questions[i].stuAnswer[2*j] = $(this).attr("id");
					data.questions[i].stuAnswer[2*j + 1] = $(this).attr("ans");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if (!nullFlag)
					nullQuesNum += ($(this).data("num")+1) + ",";
			}
			else if (QuestionType == EXAMTYPE.SORT){
				var $evt = $(this);
				var flag = false;
				$(this).find(".custom_sort_form .sort_div>li").each(function(j){
					if ($(this).next("li").length != 0){
						if ($(this).data("ordernum") == ($(this).next("li").data("ordernum") - 1)){
							flag = true;
						}else{
							flag = false;
							return false;
						}
					}	
				});
				data.questions[i].stuAnswer = new Array();
				$(this).find(".custom_sort_form .sort_div>li").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
			}
		});
		if (nullQuesNum){
			$alert("您还有题目没有完成，继续完成它吧!");	
			return;
		}
		var allNum = $("#examHL").find(".cnt").length;
		data.score = Math.round(trueNum/allNum*100);
		console.log(data);
		var studyData = {};
		studyData.courseId = GetLS("coverinfo").cid;
		studyData.chapterId = GetLS("coverinfo").chid;
		studyData.knowledgeId = GetLS("coverinfo").kid;
		$ajax({
			url:"/user/study",
			data:studyData,
			success: function(res){
				$(".tipEvt").removeClass("hide").addClass("ub");
			}
		});
	}	
}